/**
 * Created by Arter_li on 2015/6/13.
 */
module.exports = Controller("Explorer/BaseController",function(){
    'use strict';
    return{
        indexAction: function(){
            this.display();
        },
        commonjsAction:function(){
            //公共配置项输出
            var config = {"lang":"zh_CN","is_root":0,"web_root":"\/","web_host":"http:\/\/127.0.0.1\/","static_path":".\/static\/","basic_path":"D:\/wamp\/www\/kod\/","version":"3.12","app_host":"http:\/\/127.0.0.1\/kod\/","office_server":"","json_data":"","share_page":"share","theme":"simple\/","list_type":"icon","sort_field":"name","sort_order":"up","musictheme":"mp3player","movietheme":"webplayer"};
            var data =JSON.stringify(F("main",undefined,"data/i18n/zh_CN"));
            var js;
            js="LNG="+data+";";
            js+="AUTH=[];";
            js+="G="+JSON.stringify(config)+";";
            this.type("js");
            this.json(js);

        },
        loginAction: function () {
            //用户后台登陆
            if (this.isAjax("POST")) {
                var username = this.post('username');
                var password = this.post('password');
                var self = this;
                return D('user').field('password',true).where({
                    username: username,
                    password: md5(password)
                }).find().then(function (data) {
                    if (isEmpty(data)) {
                        return self.error(403, '用户名或者密码不正确');
                    } else {
                        self.session('userInfo', data);
                        return self.success({"url":self.post('reurl')});
                    }
                });

            } else {
                // console.log(this.param());

                if(this.get('g')&&this.get('c')&&this.get('a')){
                    var reurl = '/'+this.get('g')+'/'+this.get('c')+'/'+this.get('a');
                }else{
                    reurl = '/Explorer/index';
                }
                this.assign({
                    'reurl':reurl
                });
                this.display();
            }

        },
        logoutAction: function () {//退出登录
            var self = this;
            this.session().then(function () {
                return self.redirect('login');
            })
        },


    }

})